package com.shujia.wyh.day21;

import java.util.HashMap;
import java.util.Set;

/*
        HashMap<Student,String>
 */
public class HashMapDemo4 {
    public static void main(String[] args) {
        //创建集合对象
        HashMap<Student3, String> map = new HashMap<>();

        //创建几个学生对象
        Student3 s1 = new Student3("张三", 18);
        Student3 s2 = new Student3("李四", 19);
        Student3 s3 = new Student3("王五", 17);
        Student3 s4 = new Student3("张三", 18);

        //向集合中添加元素
        map.put(s1, "爬山");
        map.put(s2, "骑自行车");
        map.put(s3, "游泳");
        map.put(s4, "爬山");

        //遍历集合
        Set<Student3> keys = map.keySet();
        for (Student3 key : keys) {
            String value = map.get(key);
            System.out.println(key + ":" + value);
        }
    }
}
